package com.example.lock;

import android.content.Context;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

import com.example.lock.R;

/**
 * @ClassName: MyAnimation
 * @Description: java类作用描述
 * @Author: Shangqs
 * @CreateDate: 2021/5/27 17:12
 * @UpdateRemark: 更新说明
 */
public class MyAnimation {
    private static boolean isStart;
    private static View circle11;
    private static View circle22;
    private static View circle33;

    private static Animation animation1,animation2,animation3;

    public static void start(Context context, View circle1, View circle2, View circle3) {
        isStart = true;
        circle11=circle1;
        circle22=circle2;
        circle33=circle3;

         animation1 = AnimationUtils.loadAnimation(context, R.anim.circle_wave_anim);
         animation2 = AnimationUtils.loadAnimation(context, R.anim.circle_wave_anim);
         animation3 = AnimationUtils.loadAnimation(context, R.anim.circle_wave_anim);

        animation2.setStartOffset(1500);
        animation3.setStartOffset(3000);
        animation1.setFillAfter(true);
        animation2.setFillAfter(true);
        animation3.setFillAfter(true);

        circle1.startAnimation(animation1);
        circle2.startAnimation(animation2);
        circle3.startAnimation(animation3);


        animation1.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                circle1.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                circle1.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });

        animation2.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                circle2.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                circle2.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });


        animation3.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                circle3.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                circle3.setVisibility(View.GONE);
                if (isStart) {
                    animation2.setStartOffset(1500);
                    animation3.setStartOffset(3000);
                    circle1.startAnimation(animation1);
                    circle2.startAnimation(animation2);
                    circle3.startAnimation(animation3);
                }
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }

    public static void stopAnim() {
        isStart = false;
        circle11.clearAnimation();
        circle22.clearAnimation();
        circle33.clearAnimation();

        circle11.setVisibility(View.GONE);
        circle22.setVisibility(View.GONE);
        circle33.setVisibility(View.GONE);
    }
}
